package cn.shuto.liferay.plugin.chart.service.service.messaging;

import cn.shuto.liferay.plugin.chart.service.service.ChartTemplateLocalServiceUtil;
import cn.shuto.liferay.plugin.chart.service.service.ChartTemplateServiceUtil;
import cn.shuto.liferay.plugin.chart.service.service.ClpSerializer;
import cn.shuto.liferay.plugin.chart.service.service.DataSourceCfgLocalServiceUtil;
import cn.shuto.liferay.plugin.chart.service.service.DataSourceCfgServiceUtil;
import cn.shuto.liferay.plugin.chart.service.service.OptionLocalServiceUtil;

import com.liferay.portal.kernel.messaging.BaseMessageListener;
import com.liferay.portal.kernel.messaging.Message;


public class ClpMessageListener extends BaseMessageListener {
    public static String getServletContextName() {
        return ClpSerializer.getServletContextName();
    }

    @Override
    protected void doReceive(Message message) throws Exception {
        String command = message.getString("command");
        String servletContextName = message.getString("servletContextName");

        if (command.equals("undeploy") &&
                servletContextName.equals(getServletContextName())) {
            ChartTemplateLocalServiceUtil.clearService();

            ChartTemplateServiceUtil.clearService();
            DataSourceCfgLocalServiceUtil.clearService();

            DataSourceCfgServiceUtil.clearService();
            OptionLocalServiceUtil.clearService();
        }
    }
}
